package rs.mbs2.epics.server.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@SuppressWarnings("serial")
@Entity
@Table(name="note")
public class Note implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "note_id", unique = true, nullable = false)
	private Integer id;
	
	@Column(name = "note_caption", unique = false, nullable = false)
	private String  caption;
	
	@Column(name = "note_width", unique = false, nullable = false)
	private Integer width;
	
	@Column(name = "note_height", unique = false, nullable = false)
	private Integer height;
	
	@Column(name = "note_x", unique = false, nullable = false)
	private Integer x;
	
	@Column(name = "note_y", unique = false, nullable = false)
	private Integer y;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "photo_id", referencedColumnName = "photo_id", nullable = false)
	private Photo photo;


	public Note() {
		
	}

	public Note(String caption, Integer width, Integer height, Integer x,
			Integer y, Photo photo) {
		
		super();
		this.caption = caption;
		this.width = width;
		this.height = height;
		this.x = x;
		this.y = y;
		this.photo = photo;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public Integer getWidth() {
		return width;
	}

	public void setWidth(Integer width) {
		this.width = width;
	}

	public Integer getHeight() {
		return height;
	}

	public void setHeight(Integer height) {
		this.height = height;
	}

	public Integer getX() {
		return x;
	}

	public void setX(Integer x) {
		this.x = x;
	}

	public Integer getY() {
		return y;
	}

	public void setY(Integer y) {
		this.y = y;
	}

	public Photo getPhoto() {
		return photo;
	}

	public void setPhoto(Photo photo) {
		this.photo = photo;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((photo == null) ? 0 : photo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Note other = (Note) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (photo == null) {
			if (other.photo != null)
				return false;
		} else if (!photo.equals(other.photo))
			return false;
		return true;
	}
	
}
